# -!- coding: utf-8 -!-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
脚本类，用来对组合好的参数进行循环执行，依次带入组合参数请求。可加入对响应结果断言） 
pip install requests_toolbelt  
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

import requests
from requests_toolbelt import MultipartEncoder

from interfacetest.baseset.msydloan_api_web import API_MSYD_WEB
from msydwork.config.config_msydloan import w_url
from pycacho.cachobase.file_deal import get_file

headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36',
            'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryaL1FlMefPBCgFmnt',
            "Cookie": "admint=61f6a775d1110cc74b67b0505cd100615bcf64a2; adminhostid=2"
        }

user_cookie ={
    "1": "admint=6bb3abc5e1bc8878293117ec81a7402380efa0a9; adminhostid=1",
    "2": "admint=61f6a775d1110cc74b67b0505cd100615bcf64a2; adminhostid=2",
    "3": "admint=64b9d0c56cfb5649da4d98c82a20c40e8440e528; adminhostid=3",
    "4": "admint=5d8ab52c8ce283c49ca5265563f901a21b9af3d5; adminhostid=4",
    "5": "admint=33a964ec10555740d8ca39a1a4222f76bf942bfe; adminhostid=5"
}

# 1. 生成放款文件 application/x-www-form-urlencoded
def create_loanFile(date):
    print('---------放款文件下载开始---------')
    fc_url = w_url + '/file/loanFile/create'
    data = API_MSYD_WEB['file_create']
    data['date'] = date
    headers['Content-Type'] = 'application/x-www-form-urlencoded'
    req1 = requests.post(fc_url, data, headers=headers)
    print("接口响应信息：", req1.text)

# 2. 上传放款文件
def upload_loanFile(file,date):
    print('---------放款文件上传开始---------')
    fc_url = w_url + '/file/loanFile/upload'
    m = MultipartEncoder(
        fields={'file': (date, get_file(file) )}
    )
    headers['Content-Type'] = m.content_type
    #print(m.content_type)
    req1 = requests.post(fc_url,data=m, headers=headers)
    print("接口响应信息：", req1.text)


if __name__ == '__main__':
    #create_loanFile('20200312')
    upload_loanFile('F:\\20200621loanFile.xls','20200621')